home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / gsdbloo.exe / DEMOU003.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-23  |  3KB  |  107 lines

  1. program DemoU003;
  2. {------------------------------------------------------------------------------
  3.                               DBase Index Creator
  4.                                Useless Examples
  5.                                  Demo Program
  6.  
  7.        Copyright (c)  Richard F. Griffin
  8.  
  9.        10 February 1992
  10.  
  11.        102 Molded Stone Pl
  12.        Warner Robins, GA  31088
  13.  
  14.        -------------------------------------------------------------
  15.        Unit to demonstrate index processing.
  16.  
  17.        The DEMOU3.DBF file will be created by using the MakeTestData
  18.        procedure in GS_GENF.PAS.
  19.  
  20.        The IndexTo routine will be used to index on LASTNAME.
  21.  
  22.        The contents of the index file will be printed.
  23.  
  24.        The indexed file will be listed ascending and descending.
  25.  
  26.        Finally, Find is called using the LASTNAME in physical record
  27.        25.  The record number of the first occurrence of the name will
  28.        be returned.
  29.  
  30. -------------------------------------------------------------------------------}
  31. uses
  32.    CRT,
  33.    DOS,
  34.    printer,
  35.    GS_Strng,
  36.    GS_dBFld,
  37.    GS_dBase,
  38.    GS_GenF;
  39. var
  40.    MyFile  : GS_dBFld_Objt;
  41.    s       : string;
  42.    li      : boolean;
  43.    i       : integer;
  44.    c       : char;
  45.    ms      : string[30];
  46. begin
  47.    ClrScr;
  48.  
  49.    writeln('Creating DemoU3.DBF');
  50.    MakeTestData('DemoU3', 50, false);
  51.    writeln('DemoU3.DBF Created');
  52.  
  53.    MyFile.Init('DemoU3');
  54.    MyFile.Open;
  55.    MyFile.IndexTo('DemoU3','LASTNAME');
  56.    MyFile.Index('DemoU3');
  57.  
  58.    MyFile.dbfNdxTbl[1]^.KeyList('prn');
  59.  
  60.    i := 0;
  61.    MyFile.GetRec(Top_Record);
  62.    while (not MyFile.File_EOF) do
  63.    begin
  64.       inc(i);
  65.       if (i mod 23) = 0 then
  66.       begin
  67.          write('Press any key to continue.');
  68.          c := ReadKey;
  69.          writeln;
  70.       end;
  71.       s := MyFile.FieldGet('LASTNAME');
  72.       s[0] := #30;
  73.       writeln(MyFile.RecNumber:8,'   ',s,i:6);
  74.       MyFile.GetRec(Next_Record);
  75.    end;
  76.    writeln('End of Ascending check, Now for descending...');
  77.    writeln('Press any key to continue.');
  78.    c := ReadKey;
  79.    i := 0;
  80.    MyFile.GetRec(Top_Record);    {do this to move from end at start}
  81.    MyFile.GetRec(Bttm_Record);
  82.    while (not MyFile.File_TOF) do
  83.    begin
  84.       inc(i);
  85.       if (i mod 23) = 0 then
  86.       begin
  87.          write('Press any key to continue.');
  88.          c := ReadKey;
  89.          writeln;
  90.       end;
  91.       s := MyFile.FieldGet('LASTNAME');
  92.       s[0] := #30;
  93.       writeln(MyFile.RecNumber:8,'   ',s,i:6);
  94.       if MyFile.RecNumber = 25 then ms := s;
  95.       MyFile.GetRec(Prev_Record);
  96.    end;
  97.    ms := TrimR(ms);
  98.    li := MyFile.Find(ms);
  99.    writeln('The first record for ',ms,' is ',MyFile.RecNumber);
  100.    MyFile.Close;
  101. end.
  102.  
  103.  
  104.  
  105.  
  106.  
  107.